/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Army;

import GameObject.LayerManager;
import GameObject.Sprite;
import java.awt.Graphics2D;
import java.awt.Point;

/**
 *
 * @author Huy
 */
public abstract class ArmyEntity {
	
	public static final int[] TEAM_COLOR = new int[]{0xffff0000, 0xffffff00, 0xff00ff00, 0xff00ffff, 0xff0000ff, 0xffff00ff};
	protected final static double pi = Math.PI;
	protected Sprite sprite;
	protected boolean isDetroyed = false;
	protected int team;
	protected int size;
        
        /*protected MyTeam difTeam = new MyTeam(0);
        
        public MyTeam getDifTeam()
        {
            return difTeam;
        
        }   
        public  void setDifTeam(MyTeam value)
        {
            difTeam = value;
        }*/
	
	public int getSize() {
		return size;
	}
	
	public ArmyEntity() {
	}
	
	public int getTeam() {
		return team;
	}
	
	public boolean isIsDetroyed() {
		return isDetroyed;
	}
	
	public void detroy() {
		isDetroyed = true;
	}
	
	public Sprite getSprite() {
		return sprite;
	}
	
	public void draw(Graphics2D g) {
		draw(g, 0, 0);
		
	}
	
	public void draw(Graphics2D g, int dx, int dy) {
		sprite.draw(g, dx, dy);
	}
	
	public void move(int dx, int dy) {
		sprite.move(dx, dy);
	}
	
	public Point getPosition() {
		return sprite.getPosition();
	}
	
	public void setPosition(Point p) {
		sprite.setPosition(p);
	}

	public void setRotation(double r) {
		sprite.setRotation(r);
	}

	public void update() {
		sprite.nextFrame();
	}
	
	public static double normalizeAngle(double a) {
		double r = a;
		int n = (int) (r / (2 * pi));
		r = r - 2 * pi * n;
		if (r < 0) {
			r += 2 * pi;
		}
		return r;
	}
	
	public static double getAngle(Point p, Point pTarget) {
		double dx = pTarget.x - p.x;
		double dy = pTarget.y - p.y;
		if (dy == 0) {
			dy = 0.01;
		}
		double r = Math.atan(-dx / dy);
		if (dy > 0) {
			r = pi + r;
		}
		return r;
	}
}
